#ifndef _SHARE_H
#define _SHARE_H 1

#include <stdbool.h>
#include <openssl/ssl.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <error.h>

#define STATUS_INIT (1<<0)
#define STATUS_CONN (1<<1)
#define STATUS_ENC (1<<2)
#define STATUS_SRV (1<<3)
#define STATUS_CLI (1<<4)
#define STATUS_INIT_ERROR (1<<5)
#define STATUS_READ_ERROR (1<<6)
#define STATUS_WRITE_ERROR (1<<7)
#define STATUS_MAIN_SRV (1<<8)
#define ERROR_UNRECOVERABLE (1<<9)
#define STATUS_PTHREAD (1<<10)

typedef struct sock_t {

 int _sockfd; // Socket file descriptor
// bool _encrypted; //deprecated
// unsigned int status; //deprecated
 unsigned short _status; // Status of the socket
 char cert[1024];
 char key[1024];
 SSL_CTX *_ssl_ctx; // SSL Context
 SSL *_ssl; // SSL pointer
 unsigned int last_read; // Size of last read
 unsigned int last_write; // Size of last write
 struct sockaddr_in _their_addr; // Opposite side's IP address
 char _error_message[255]; // Error message for socket

} SOCK;

//char g_error_message[255]; //deprecated

void err(char *, SOCK *);
void print_err(SOCK *);
int share_send(SOCK *, char *);
char *share_read(SOCK *, int);
void _init_socket_variable(SOCK *);
int share_close_gracefully(SOCK *);
void share_make_pthread(SOCK *);

#endif
